<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

  <style>
    /* ::-webkit-scrollbar {
      width: 8px;
      height: 8px;
      background: #00000011;
    }

    ::-webkit-scrollbar-thumb {
      border-radius: 8px;
      background: #00000033;
    }

    ::-webkit-scrollbar-thumb:hover {
      background: #00000055;
    }

    ::-webkit-scrollbar-corner {
      background: none;
    } */

    .scrollContainer {
      width: 900px;
      height: 400px;
      overflow: auto;

    }

    .dragContainer {
      height: 2000px;
      width: 2000px;
      background: url('./1.png') no-repeat;
    }


    .dragContainer {
      cursor: grab;
    }

    .dragContainer:active {
      cursor: grabbing;
      user-select: none
    }
  </style>
</head>

<body>
  <div class="scrollContainer">
    <div class="dragContainer">
    </div>
  </div>
</body>

</html>
<script>

  let scrollContainer = document.querySelector(".scrollContainer")
  let dragContainer = document.querySelector(".dragContainer");
  dragContainer.onmousedown = e => {
    //鼠标按下那一刻，滚动条的位置
    let mouseDownScrollPosition = {
      scrollLeft: scrollContainer.scrollLeft,
      scrollTop: scrollContainer.scrollTop
    };
    //鼠标按下的位置坐标
    let mouseDownPoint = {
      x: e.clientX,
      y: e.clientY
    };
    dragContainer.onmousemove = e => {
      //鼠标滑动的实时距离
      let dragMoveDiff = {
        x: mouseDownPoint.x - e.clientX,
        y: mouseDownPoint.y - e.clientY
      };
      scrollContainer.scrollLeft = mouseDownScrollPosition.scrollLeft + dragMoveDiff.x;
      scrollContainer.scrollTop = mouseDownScrollPosition.scrollTop + dragMoveDiff.y;
    };
    document.onmouseup = e => {
      dragContainer.onmousemove = null;
      document.onmouseup = null;
    };
  };
</script>